package test;

import static org.junit.Assert.*;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import dao.BorrowDao;
import dao.impl.BorrowDaoImpl;
import model.Borrow;

public class BorrowDaoTset {
	private static BorrowDao bwd;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		bwd = new BorrowDaoImpl();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testgetAllBorrow() throws SQLException {
		List<Borrow> list = new ArrayList<Borrow>();
		list = bwd.getAllBorrow();
		for(int i=0; i < list.size(); i++) {
			Borrow borrow = list.get(i);
			System.out.println(borrow.getUserId()+","
			+borrow.getBookIsbn()+","
			+borrow.getBookName()+","
			+borrow.getBorrowTime()+","
			+borrow.getBorrowReturn()+","
			+borrow.getBorrowState());
		}		
	}
	
//	@Test
//	public void testborrowBook() throws SQLException {
//		Borrow borrow = new Borrow();
//		borrow.setUserId("1712205121");
//		borrow.setBookIsbn("974696654");
//		borrow.setBorrowDuration(Integer.parseInt("30"));
//		assertEquals(true, bwd.borrowBook(borrow));
//	}
//	@Test
//	public void testadminAgreeBorrow() throws SQLException {
//		Borrow borrow = new Borrow();
//		borrow.setUserId("123");
//		borrow.setBookId("3");
//		assertEquals(true, bwd.adminAgreeBorrow(borrow));
//	}
	@Test
	public void testgetBorrowByUserId() throws SQLException {
		List<Borrow> list = new ArrayList<Borrow>();
		list = bwd.getBorrowByUserId("1712205121");
		for(int i=0; i < list.size(); i++) {
			Borrow borrow = list.get(i);
			System.out.println(borrow.getBookName()+","
					+borrow.getBookIsbn()+","
					+borrow.getBorrowTime()+","
					+borrow.getBorrowReturn()+","
					+borrow.getBorrowState());
		}
	}
	
//	@Test
//	public void testreturnBook() throws SQLException {
//		Borrow borrow = new Borrow();
//		borrow.setUserId("123");
//		borrow.setBookId("3");
//		assertEquals(true, bwd.returnBook(borrow));
//	}
//	
	
	
	
	
}
